package com.heima.media.controller;


import com.heima.common.dto.ResponseResult;

import com.heima.media.dto.ChannelDto;
import com.heima.media.entity.WmChannel;
import com.heima.media.service.IWmChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
@Api(tags = "频道管理API")
public class WmChannelController {
    @Autowired
    private IWmChannelService wmChannelService;
//    频道的分液查询
    @PostMapping("/list")
    @ApiOperation(value = "根据名称模糊查询分页列表",notes = "author:mcm")
    @ApiImplicitParam(name="dto",value = "查询对象",required = true,dataType = "ChannelDto")
    public ResponseResult listByName(@RequestBody ChannelDto dto){
        return wmChannelService.listByName(dto);
    }
//    频道的添加
    @PostMapping
    @ApiOperation(value = "新增频道",notes="author:mcm")
    @ApiImplicitParam(name ="wmChannel",value ="频道对象",required = true,dataType ="WmChannel")
    public ResponseResult saveWmChannel(@RequestBody WmChannel wmChannel){
        return wmChannelService.saveWmChannel(wmChannel);   }
//        频道的修改
    @PutMapping
    @ApiOperation(value = "修改频道",notes="author:mcm")
    @ApiImplicitParam(name ="wmChannel",value ="频道对象",required = true,dataType ="WmChannel")
    public  ResponseResult updateWmChannel(@RequestBody WmChannel wmChannel){
             wmChannelService.updateById(wmChannel);
             return ResponseResult.okResult();


        }
//        频道的删除
@DeleteMapping("/{id}")
@ApiOperation(value = "删除频道",notes="author:mcm")
@ApiImplicitParam(name ="wmChannel",value ="频道对象",required = true,dataType ="WmChannel")
public  ResponseResult updateWmChannel(@PathVariable Integer id){
    wmChannelService.removeById(id);
    return ResponseResult.okResult();


}
//查询所有的频道
    @GetMapping("/channels")
    public ResponseResult channels(){
        List<WmChannel> list = wmChannelService.list();
        return ResponseResult.okResult(list);
    }





}
